#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int Max = 0, fixed = 0;
    for (int i = 0; i < n; i++)
    {
        if (i + 1 < n && abs(v[i + 1] - v[i]) <= 8)
        {
            fixed = i;
            int left = i, right = i + 1;
            while (right < n && abs(v[right] - v[left]) <= 8)
            {
                left++;
                right++;
            }
            Max = max(Max, right - fixed);
        }
    }
    cout << Max << endl;

    return 0;
}